﻿using Amazon;
using Amazon.S3;
using Amazon.S3.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Utilities
{
    public class AWSS3Explorer
    {
        private AWSAuthentication authenticate { get; set; }
        private AmazonS3 s3 { get; set; }

        public AWSS3Explorer() { }

        public AWSS3Explorer(AWSAuthentication authenticate) { this.authenticate = authenticate; }

        public bool IsValid()
        {
            if (s3 == null)
            {
                AWSLogger.Write("S3 is null.", null, LogType.WARN);
                return false;
            }
            else
            {
                return true;
            }
        }

        public void Initialize()
        {
            if (!IsValid())
            {                
                s3 = AWSClientFactory.CreateAmazonS3Client(authenticate.GetAccessKey(), authenticate.GetSecretKey());
                AWSLogger.Write("S3 Initialized.", null, LogType.TRACE);
            }
        }

        public IEnumerable<S3Bucket> GetAllBuckets()
        {
            try
            {
                if (IsValid())
                {
                    AWSLogger.Write("Fetching all available buckets.", null, LogType.TRACE);
                    var buckets = s3.ListBuckets();
                    return buckets.Buckets;
                }
                return null;
            }
            catch (Exception aws)
            {
                AWSLogger.Write("Failed to retrieve buckets.", aws, LogType.ERROR);
                return null;
            }
        }

        public void methos()
        {
            try
            {
                if (IsValid())
                {
                    
                }
            }
            catch (Exception aws)
            {
                AWSLogger.Write("Failed to retrieve buckets.", aws, LogType.ERROR);
            }
        }
    }
}
